
********FIRST FIVE COLUMNS********
est clear

use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
drop if missing(convexity_split)
drop if missing(futexcess)

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

*convexity split rank
gen convex_five=.
sort monthyear convexity_split
by monthyear: replace convex_five=1 if _n<_N/5
by monthyear: replace convex_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace convex_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace convex_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace convex_five=5 if _n>=_N/5*4

replace futexcess=futexcess*100

egen vw_excess=wtmean(futexcess),  weight(mktcap) by(monthyear convex_five)

*consolidate to one observation per month
sort convex_five monthyear 
collapse vw_excess, by(convex_five monthyear)

tsset convex_five monthyear  

merge m:1 monthyear using "$jfqa_rep/FF5_Monthly_Factors.dta"
drop if _merge==2
drop _merge

merge m:1 year month using "$jfqa_rep/FF_REV_UMD.dta"
drop if _merge==2
drop _merge 

merge m:1 year month using "$jfqa_rep/PS_Factors.dta"
drop if _merge==2
drop _merge

replace year=1963 if missing(year)
replace month=6 if missing(month)
replace monthyear=ym(year, month)

sort convex_five monthyear 
foreach i in mktrf smb hml rmw cma rf strev mom ltrev level innov traded {
	replace fut`i'=F.`i' if missing(fut`i')
}			

*CAPM
forval i=1/5 {
	eststo: newey vw_excess futmktrf if convex_five ==`i', lag(6)
}

*FF3
forval i=1/5 {
	eststo: newey vw_excess futmktrf futsmb futhml if convex_five ==`i', lag(6)
}

*FF5
forval i=1/5 {
	eststo: newey vw_excess futmktrf futsmb futhml futrmw futcma if convex_five ==`i', lag(6)
}

*FF5+UMD
forval i=1/5 {
	eststo: newey vw_excess futmktrf futsmb futhml futrmw futcma futmom if convex_five ==`i', lag(6)
}

*FF5+SREV
forval i=1/5 {
	eststo: newey vw_excess futmktrf futsmb futhml futrmw futcma futstrev if convex_five ==`i', lag(6)
}

*FF5+LREV
forval i=1/5 {
	eststo: newey vw_excess futmktrf futsmb futhml futrmw futcma futltrev if convex_five ==`i', lag(6)
}

*FF5+LIQ
forval i=1/5 {
	eststo: newey vw_excess futmktrf futsmb futhml futrmw futcma futtraded if convex_five ==`i', lag(6)
}
}



********LAST COLUMN********
use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
drop if missing(convexity_split)
drop if missing(futexcess)

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

*convexity split rank
gen convex_five=.
sort monthyear convexity_split
by monthyear: replace convex_five=1 if _n<_N/5
by monthyear: replace convex_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace convex_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace convex_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace convex_five=5 if _n>=_N/5*4

replace futret=futret*100
replace futexcess=futexcess*100

egen vw_raw=wtmean(futret), weight(mktcap) by(monthyear convex_five)
egen vw_excess=wtmean(futexcess),  weight(mktcap) by(monthyear convex_five)

*consolidate to one observation per month
sort convex_five monthyear 
collapse vw_raw vw_excess, by(convex_five monthyear)

tsset convex_five monthyear  

keep if convex_five==1 | convex_five==5

sort monthyear convex_five

gen vw_excess_dif=vw_excess-vw_excess[_n+1] if convex_five==1

merge m:1 monthyear using "$jfqa_rep/FF5_Monthly_Factors.dta"
drop if _merge==2
drop _merge

merge m:1 year month using "$jfqa_rep/FF_REV_UMD.dta"
drop if _merge==2
drop _merge 

merge m:1 year month using "$jfqa_rep/PS_Factors.dta"
drop if _merge==2
drop _merge

replace year=1963 if missing(year)
replace month=6 if missing(month)
replace monthyear=ym(year, month)

sort convex_five monthyear 
foreach i in mktrf smb hml rmw cma rf strev mom ltrev level innov traded {
	replace fut`i'=F.`i' if missing(fut`i')
}			

*CAPM
eststo: newey vw_excess_dif futmktrf, lag(6)

*FF3
eststo: newey vw_excess_dif futmktrf futsmb futhml, lag(6)

*FF5
eststo: newey vw_excess_dif futmktrf futsmb futhml futrmw futcma, lag(6)

*FF5+UMD
eststo: newey vw_excess_dif futmktrf futsmb futhml futrmw futcma futmom, lag(6)

*FF5+SREV
eststo: newey vw_excess_dif futmktrf futsmb futhml futrmw futcma futstrev, lag(6)

*FF5+LREV
eststo: newey vw_excess_dif futmktrf futsmb futhml futrmw futcma futltrev, lag(6)

*FF5+LIQ
eststo: newey vw_excess_dif futmktrf futsmb futhml futrmw futcma futtraded, lag(6)
}

esttab using "$jfqa_rep/Table_4.csv", nostar replace b(2)
